<?php
/**
 * Created by PhpStorm.
 * User: qingyun
 * Date: 18/12/14
 * Time: 下午4:58
 */

namespace think;



$fileInfo = $_FILES;
//$fileInfo2 = $_FILES['img2'];
$first = current($fileInfo);
print_r($fileInfo);

print_r($first['name']);
echo '<br>';

//exit;


if(is_array($first['name'])){
    foreach ($first['name'] as $k=>$v){

        if (empty($v)){
            continue;
        }else{
            print_r($newDate[$k]['name'] = $first['name'][$k]);
            print_r($newDate[$k]['type'] = $first['type'][$k]);
            print_r($newDate[$k]['tmp_name'] = $first['tmp_name'][$k]);
            print_r($newDate[$k]['error'] = $first['error'][$k]);
            print_r($newDate[$k]['size'] = $first['size'][$k]);
            echo '<br>';
        }
    }
}else{
    $newDate = $fileInfo;
}

print_r($newDate);


exit;

class Upload
{
    public $errInfo;

    //上传一个
    public function uploadOne(array $fileInfo){
        //创建并判断上传文件的储存路径
        if ($fileInfo['error'] == 0){
            $dir = './upload/';
            $todayDir = $dir.date('Ymd').'/';
            if (!file_exists($todayDir)){
                if (!mkdir($todayDir)){
                    $this->errInfo = $todayDir.'没有写入的权限';
                    return false;
                }

            }


        //截取文件的后缀名

        $tmp = explode('.',$fileInfo['name']);
//            print_r($tmp);
        $endName = end($tmp);
//        print_r($endName);
//        exit;

        //限制文件上传类型
        $allow = ['flv','wmv','rar','png','zip','jpeg','jpg'];
        if (!in_array($endName,$allow)){
            $this->errInfo = $fileInfo['name'].'不允许上传此类文件,所有文件上传失败';
            return false;
        }

        //生成新的文件名
        $newName = time().'.'.$endName;

        //限制上传文件的大小
        $maxSize = 2 * 1024 * 1024;
        if ($fileInfo['size'] > $maxSize){
            $this->errInfo = '文件'.$fileInfo['name'].'过大上传失败';
            return false;
        }

        //判断文件是否被转移成功
        if (move_uploaded_file($fileInfo['tmp_name'],$todayDir.$newName)){
            echo '上传成功';
            return true;
         }else{
            $this->errInfo = $fileInfo['name'].'所有文件上传失败';
            return false;
        }

        }else{
            $this->errInfo = '非法操作';
            return false;
        }

    }

    public function up()
    {
        $data = $_FILES;
        $firsr = current($data);
    }
















}


$n = new Upload();
$n->uploadOne($fileInfo);
print_r($n->errInfo);

